/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: dell
 * Date: 2024-01-10
 * Time: 11:23
 */
public class Queue {
    int[] list;
    int front;
    int rear;
    int unsize;
    public Queue(int k) {
        this.list=new int[k];
        this.unsize=0;
    }

    public boolean enQueue(int value) {
        if(isFull()){
            return false;
        }
        list[rear]=value;
        rear=(rear+1)%list.length;
        this.unsize++;
        return true;
    }

    public boolean deQueue() {
        if(isEmpty()){
            return false;
        }
        front=(front+1)%list.length;
        this.unsize--;
        return true;
    }

    public int Front() {
        if(isEmpty()){
            return -1;
        }
        return list[front];

    }

    public int Rear() {
        if(isEmpty()){
            return -1;
        }
        int num=(rear==0) ? list.length-1:rear-1;
        return list[num];
    }

    public boolean isEmpty(){
        return unsize==0;
    }

    public boolean isFull() {
        return unsize==list.length;
    }
}
